using HKB.Common;
using HKB.Data.Dal.S_ProductLikeCategoryTableAdapters;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class Shop_ProductLikeCategory
	{
		private Conn conn = null;
		private static readonly HLShop_ProductLikeCategoryTableAdapter Adapter = new HLShop_ProductLikeCategoryTableAdapter();
		public Shop_ProductLikeCategory()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public Shop_ProductLikeCategory(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetProductLikeCategory(int ShopID)
		{
			return Shop_ProductLikeCategory.Adapter.GetProductLikeCategory(new int?(ShopID));
		}
		public void DeleteProductLikeCategory(int ShopProductClassID)
		{
			Shop_ProductLikeCategory.Adapter.DeleteProductLikeCategory(ShopProductClassID);
		}
		public bool InsertProductLikeCategory(int shopid, string ShopProductClassName, int orderby)
		{
			int num = 10;
			string text = Shop_ProductLikeCategory.Adapter.CountNumsByShopID(new int?(shopid)).ToString();
			bool result;
			if (text != "" && text != null)
			{
				if (int.Parse(text) < num)
				{
					int num2 = Shop_ProductLikeCategory.Adapter.InsertProductLikeCategory(new int?(shopid), ShopProductClassName, new int?(orderby));
					result = (num2 == 1);
					return result;
				}
			}
			result = false;
			return result;
		}
		public bool IsSame(int ShopID, int OrderBy, string CategoryName)
		{
			Shop_ProductLikeCategory shop_ProductLikeCategory = new Shop_ProductLikeCategory();
			DataTable productLikeCategory = shop_ProductLikeCategory.GetProductLikeCategory(ShopID);
			bool result;
			for (int i = 0; i < productLikeCategory.Rows.Count; i++)
			{
				int num = (int)productLikeCategory.Rows[i]["OrderBy"];
				string b = productLikeCategory.Rows[i]["ShopProductClassName"].ToString();
				if (OrderBy == num || CategoryName == b)
				{
					result = true;
					return result;
				}
			}
			result = false;
			return result;
		}
		public void UpdateProductLikeCategory(string ShopProductClassName, int orderby, int ShopProductClassID)
		{
			Shop_ProductLikeCategory.Adapter.UpdateProductLikeCategory(ShopProductClassName, new int?(orderby), ShopProductClassID);
		}
		public DataTable GetShopProductClassByShopProductClassID(int ShopProductClassID)
		{
			return Shop_ProductLikeCategory.Adapter.GetShopProductByShopProductCategoryID(new int?(ShopProductClassID));
		}
		public DataTable GetShop_ProductLikeCategorybyCategoryIDShopID(int ShopID, int ShopProductClassID)
		{
			return Shop_ProductLikeCategory.Adapter.GetShop_ProductLikeCategorybyCategoryIDShopID(new int?(ShopID), ShopProductClassID);
		}
		public bool UpdateShopCategory(int OldCategoryid, int newCategoryid, string olarryproductid, string newarryproductid)
		{
			int num = Shop_ProductLikeCategory.Adapter.UpdateShopCategrory(new int?(OldCategoryid), new int?(newCategoryid), olarryproductid, newarryproductid);
			return num == 1;
		}
		public int CountByShopID(int ShopID)
		{
			if (this.conn == null)
			{
				this.conn = new Conn();
			}
			if (!this.conn.Connected)
			{
				this.conn.OpenConn();
			}
			return this.conn.ExecuteCount("Select count(*) From HLShop_ProductLikeCategory Where ShopID=" + ShopID);
		}
		public DataTable GetProductCategoryByShopID(int shopID)
		{
			DataTable result = null;
			if (shopID > 0)
			{
				string sql = "select * from HLShop_ProductLikeCategory where ShopID=" + shopID + " order by orderby asc";
				result = this.conn.GetDataTable(sql);
			}
			return result;
		}
	}
}
